$(document).ready(function(){
	//顶部滚动事件
	var $header = $('#header');
	var $header_replave = $('#header-replace');
	var $header_bstop = true;
	$header_replave.animate({
		'opacity':'0'
	},2000);
	var $scrolltopOld = $(document).scrollTop();
	$(window).scroll(()=>{
		let $scrolltop = $(document).scrollTop();
        if ($scrolltop > $header.outerHeight()){$header.addClass('gizle');} 
        else {$header.removeClass('gizle');}

        if ($scrolltop > $scrolltopOld){
        	if ($(document).scrollTop() >= $(document).height() - $(window).height()){
        	$header.addClass('sabit');
	        }else {
	        	$header.removeClass('sabit');
	        }
    	} 
        else {$header.addClass('sabit');}				
        $scrolltopOld = $(document).scrollTop();	
	})
	//侧边栏显示与消失
	var $side_btn = $('#btn-more-y');
	var $side_box = $('#box_move-y');
	var bstop_sidebar = true;
	$side_btn.on('mouseenter',function(){
		if(bstop_sidebar){
			$side_box.animate({
				right:'0px'
			},500,()=>{
				bstop_sidebar = false;
			});
		}
	})
	$side_box.on('mouseleave',(e)=>{
			console.log(1);
			$side_box.animate({
				right:'-280px'
			},800,()=>{
				bstop_sidebar = true;
			});
	})
	//侧边按钮的显示与消失
	$(window).scroll(()=>{
		if($(document).scrollTop() <= $imgHeight) {
			$side_btn.fadeOut();
		}else {
			$side_btn.fadeIn();
		}
	})

	//右侧搜索栏
	

	//下拉切换第一屏
	const $dropdown_tips_y = $('#dropdown-tips-y');
	//这里需要动态的获取当前图片的高度(更加完善的话应该加一个屏幕变化的事件来改变高度的值)
	const $imgHeight = $('.carousel-inner').height();
	$dropdown_tips_y.on('click',()=>{
		var $tips_top = 0;
		let $tips_top_timer = setInterval(function(){
			if($tips_top >= $imgHeight){
				$tips_top = $imgHeight;
				clearInterval($tips_top_timer);
				$side_btn.fadeIn();
			}
			$tips_top += 10;
			$('html,body').scrollTop($tips_top);
		},4);
	})
})

//底部的js
const $footer_wechat_y = $('#footer-wechat-y');
const $img_wechat_y = $('#img-wechat-y');
$footer_wechat_y.on('mouseenter',()=>{
	$img_wechat_y.fadeIn();
})
$footer_wechat_y.on('mouseout',()=>{
	$img_wechat_y.fadeOut();
})

//ajax获取数据
$.ajax({
	type : "POST",
	url : "http://localhost:3000/content/list",
	success : function (data) {
		let contentHtml = "";
		let contentLength = data.rows.length;
		let $contentParent = $('#contentParent') 
		for (var index = 0; index < contentLength; index++) {
			contentHtml += `<div class="flex-leftRight-y">
                            <h4 class="title"><a href="javascript:void(0);">${data.rows[index].title}</a></h4>
                            <div class="auther">
                                <span>作者：<a href="javascript:void(0);">${data.rows[index].author}</a></span>
                                ·<span>2017年10月1日</span>
                            </div>
                            <h4 class="other-title"><a href="javascript:void(0);">副标题-编者安</a></h4>
                            <div class="content">
                                <p>${data.rows[index].otherTitle}</p>
                            </div>
                            <div class="btn-more">
                                <a href="javascript:void(0);">阅读全文</a>
                            </div>
                            <hr>
                            <div class="tips">
                                <i class="iconfont">&#xe95c;</i>
                                <a href="javascript:void(0)">${data.rows[index].tips[0]}</a>,
                                <a href="javascript:void(0)">${data.rows[index].tips[1]}</a>
                            </div>
                        </div>`
			
		}
		$contentParent.html(contentHtml);
		
		console.log(data.rows.length);
	}
});